import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutter_hx/services/app_theme_services.dart';
import 'package:flutter_hx/widgets/image_widget.dart';
import 'package:flutter_hx/widgets/user_avatar_widget.dart';
import 'package:flutter_hx/widgets/view_state_helper.dart';
import 'package:get/get.dart';

import 'me_team_logic.dart';

class MeTeamPage extends GetView<MeTeamLogic> {
  const MeTeamPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    controller.onRefresh();
    return Scaffold(
      backgroundColor: AppThemeServices.appColors.background,
      appBar: AppBar(
        backgroundColor: AppThemeServices.appColors.background,
        elevation: 0,
        automaticallyImplyLeading: true,
        iconTheme:const IconThemeData(
            color: Colors.black
        ),
        centerTitle: true,
        title: Text("我的团队",style: AppThemeServices.textTheme.appBarTitle),
      ),
      body:  AnnotatedRegion<SystemUiOverlayStyle>(
        value: SystemUiOverlayStyle.dark,
        child:Padding(
          padding: const EdgeInsets.symmetric(horizontal: 10,vertical: 10),
          child: Obx((){
            Widget? contentWidget;
            switch(controller.viewStatus.value){
              case ViewState.error:
              case ViewState.noNetwork:
                contentWidget=Center(child: ViewStateErrorWidget(onPressed:()=>controller.onRefresh(),paddingTop: 20));
                break;
              case ViewState.empty:
                contentWidget=const Center(child: ViewStateEmptyWidget());
                break;
              case ViewState.loading:
                contentWidget=const Center(child: ViewStateLoadingWidget());
                break;
            }
            return Column(
              children: [
                Container(
                  width: double.infinity,
                  padding: const EdgeInsets.only(left: 15,right: 15,bottom: 10,top: 20),
                  decoration: BoxDecoration(
                      gradient: const LinearGradient(
                          colors: [
                            Color.fromRGBO(52, 216, 194, 1),
                            Color.fromRGBO(25, 205, 185, 1)
                          ]
                      ),
                      color:const Color.fromRGBO(0, 141, 57, 1),
                      borderRadius: BorderRadius.circular(14.53)
                  ),
                  child: Column(
                    children: [
                      Text("团队总人数",style: AppThemeServices.textTheme.h14.copyWith(color: Colors.white,fontWeight: FontWeight.w700)),
                      const SizedBox(height: 7),
                      Text("${controller.team["totalCount"]??"0"}",style: AppThemeServices.textTheme.h32.bold().copyWith(color: Colors.white,fontSize: 30)),
                      const SizedBox(height: 10),
                      Container(
                        padding: const EdgeInsets.symmetric(vertical: 10),
                        decoration: BoxDecoration(
                            color:const  Color.fromRGBO(255, 255, 255, 0.2600),
                            borderRadius: BorderRadius.circular(7.5)
                        ),
                        child: Row(
                          children: [
                            Expanded(child: Column(
                              children: [
                                Text("直推人数",style: AppThemeServices.textTheme.h12.copyWith(color: Colors.white)),
                                const SizedBox(height: 3),
                                Text("${controller.team["shareCount"]??"0"}",style: AppThemeServices.textTheme.h20.bold().copyWith(color: Colors.white,fontWeight: FontWeight.w500)),
                              ],
                            )),
                            Expanded(child: Column(
                              children: [
                                Text("间推人数",style: AppThemeServices.textTheme.h12.copyWith(color: Colors.white)),
                                const SizedBox(height: 3),
                                Text("${controller.team["teamCount"]??"0"}",style: AppThemeServices.textTheme.h20.bold().copyWith(color: Colors.white,fontWeight: FontWeight.w500)),
                              ],
                            )),
                            Expanded(child: Column(
                              children: [
                                Text("团队总业绩",style: AppThemeServices.textTheme.h12.copyWith(color: Colors.white)),
                                const SizedBox(height: 3),
                                Text("${controller.team["teamContribution"]??"0.00"}",style: AppThemeServices.textTheme.h20.bold().copyWith(color: Colors.white,fontWeight: FontWeight.w500)),
                              ],
                            ))
                          ],
                        ),
                      )
                    ],
                  ),
                ),
                const SizedBox(height: 15),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text("团队列表",style: AppThemeServices.textTheme.h16.bold().copyWith(color: AppThemeServices.appColors.primarilyTextColor)),
                    Row(
                      children: [
                        Text("全部",style: AppThemeServices.textTheme.h13.copyWith(color: AppThemeServices.appColors.hintTextColor)),
                        const SizedBox(width: 5),
                        Icon(Icons.arrow_drop_down_sharp,size: 24,color: AppThemeServices.appColors.hintTextColor)
                      ],
                    )
                  ],
                ),
                const SizedBox(height: 10),
                Expanded(child:contentWidget??EasyRefresh.custom(
                  header: ClassicalHeader(),
                  footer: ClassicalFooter(),
                  onRefresh: ()=>controller.onRefresh(),
                  onLoad: ()=>controller.onLoad(),
                  controller: controller.refreshController,
                  slivers: [
                    SliverList(delegate: SliverChildBuilderDelegate((_,i){
                      final item=controller.dataSource[i];
                      final isAuthName=item["isAuthName"] as bool;
                      return Container(
                        padding: const EdgeInsets.symmetric(horizontal: 10,vertical: 15),
                        margin: const EdgeInsets.only(bottom: 10),
                        decoration: BoxDecoration(
                          color: Colors.white,
                          borderRadius: BorderRadius.circular(7.5)
                        ),
                        child: Column(
                          children: [
                            Row(
                              children: [
                                UserAvatarWidget(avatar: item["portrait"]??"",size: 25),
                                const SizedBox(width: 6),
                                Text("${item["nickName"]??""}",style: AppThemeServices.textTheme.h15.copyWith(color: AppThemeServices.appColors.primarilyTextColor,fontWeight: FontWeight.w500)),
                                Text(isAuthName?"(已实名)":"(未实名)",style: AppThemeServices.textTheme.h13.copyWith(color: isAuthName?const Color.fromRGBO(0, 195, 179, 1):const Color.fromRGBO(255, 188, 42, 1)),)
                              ],
                            ),
                            const SizedBox(height: 15),
                            const Divider(color: Color.fromRGBO(242, 242, 242, 1),height: 0.5),
                            const SizedBox(height: 15),
                            Row(
                              children: [
                                Expanded(child: Column(
                                  children: [
                                    Text("${item["shareCount"]}",style: AppThemeServices.textTheme.h15.copyWith(color: AppThemeServices.appColors.primarilyTextColor)),
                                    const SizedBox(height: 5),
                                    Text("直推人数",style: AppThemeServices.textTheme.h12.copyWith(color: AppThemeServices.appColors.hintTextColor)),
                                  ],
                                )),
                                Expanded(child: Column(
                                  children: [
                                    Text("${(item["teamCount"] as int)-(item["shareCount"] as int)}",style: AppThemeServices.textTheme.h15.copyWith(color: AppThemeServices.appColors.primarilyTextColor)),
                                    const SizedBox(height: 5),
                                    Text("间推人数",style: AppThemeServices.textTheme.h12.copyWith(color: AppThemeServices.appColors.hintTextColor)),
                                  ],
                                )),
                                Expanded(child: Column(
                                  children: [
                                    Text("${item["teamContribution"]}",style: AppThemeServices.textTheme.h15.copyWith(color: AppThemeServices.appColors.primarilyTextColor)),
                                    const SizedBox(height: 5),
                                    Text("团队业绩",style: AppThemeServices.textTheme.h12.copyWith(color: AppThemeServices.appColors.hintTextColor)),
                                  ],
                                ))
                              ],
                            )
                          ],
                        ),
                      );
                    },childCount: controller.dataSource.length))
                  ],
                ))
              ],
            );
          }),
        ),
      ),
    );
  }
}
